package com.har.modules.web.controller;


import com.har.common.exception.RRException;
import com.har.common.utils.R;
import com.har.modules.web.entity.ApplyEntity;
import com.har.modules.web.entity.CommonEntity;
import com.har.modules.web.service.BaseProducService;
import com.har.modules.web.service.LoanService;
import com.har.modules.web.service.RegiserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

/**
 *
 * 保险
 *
 * @author maorui
 */
@Slf4j
@RestController
@RequestMapping("/insurance")
public class InsuranceController {


    @Autowired
    private RegiserService regiserService;

    @Autowired
    private LoanService loanService;

    @Autowired
    private BaseProducService baseProducService;

    /**
     *
     *   通过id查询保险详细信息
     * @param id
     * @return
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        CommonEntity commonEntity=loanService.selectById(id);
        if (null==commonEntity) {
            throw new RRException("查询出错");
        }
        return R.ok().put("data", commonEntity);
    }

    /**
     *    保险页面申请
     * @param regiserEntity
     * @param
     * @return
     */
    @RequestMapping("/save")
    public R save(@RequestBody ApplyEntity regiserEntity, HttpServletRequest request) throws ParseException {
        regiserEntity.setProductTypeName("保险");

        //保存申请内容
        regiserService.save(regiserEntity,request);

        return R.ok();
    }

    /**
     * wechat端查询保险模块
     * @return
     */
    @RequestMapping("/wechat/list")
    public R queryInsuranceList(){

        return R.ok().put("data",baseProducService.queryInsuranceList());
    }
}
